<template>
  <div class="container">
    <navBar :title="'隐患详情'" :backStep="'mySubmitIndex'"></navBar>
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="item in imgList" :key="item"
        ><img class="swiperImg" :src="item" alt=""
      /></van-swipe-item>
    </van-swipe>
    <div class="mainBox">
      <div class="title">
        <div>{{ formInfoObj?.dangerName }}</div>
        <div class="status">{{ formInfoObj.changeStatusName }}</div>
      </div>

      <div class="problemDesc">
        {{ formInfoObj.dangerDescribe }}
      </div>

      <div class="formBox">
        <div class="formItem">
          <van-cell title="隐患名称:">
            <template #default>
              <div>{{ formInfoObj?.dangerName }}</div>
            </template>
          </van-cell>
          <van-cell title="隐患来源:">
            <template #default>
              <div>{{ formInfoObj.dangerSourceName }}</div>
            </template>
          </van-cell>
          <van-cell title="隐患类别:">
            <template #default>
              <div>{{ formInfoObj.dangerKindName }}</div>
            </template>
          </van-cell>
        </div>
        <div class="formItem">
          <van-cell title="治理类型:">
            <template #default>
              <div>{{ formInfoObj.governKindName }}</div>
            </template>
          </van-cell>
          <van-cell title="隐患治理期间:">
            <template #default>
              <div>{{ formInfoObj.governTime }}天</div>
            </template>
          </van-cell>
        </div>
        <div class="formItem">
          <van-cell title="登记人:">
            <template #default>
              <div>{{ formInfoObj.checkName }}</div>
            </template>
          </van-cell>
          <!-- <van-cell title="联系方式:">
            <template #default>
              <div>{{formInfoObj.dangerName}}</div>
            </template>
          </van-cell> -->
          <van-cell title="登记时间:">
            <template #default>
              <div>{{ formInfoObj.checkTime }}</div>
            </template>
          </van-cell>
        </div>

        <div
          class="formItem"
          v-if="formInfoObj.changeStatus == 2 || formInfoObj.changeResponerTime"
        >
          <van-cell title="整改负责人:">
            <template #default>
              <div>{{ formInfoObj.changeResponerName }}</div>
            </template>
          </van-cell>

          <van-cell title="整改完成时间:">
            <template #default>
              <div>{{ formInfoObj.changeResponerTime }}</div>
            </template>
          </van-cell>
          <van-cell title="联系方式:">
            <template #default>
              <div>{{ formInfoObj.changeResponerPhone }}</div>
            </template>
          </van-cell>
          <div class="cellCss">
            <div class="cellCssTitle">整改图片:</div>
            <div>
              <van-uploader
                v-model="imgList2"
                :max-count="3"
                disabled
                :show-upload="false"
                :deletable="false"
              />
            </div>
          </div>
        </div>
        <div class="formItem" v-if="formInfoObj.checkResponerRemark">
          <van-cell title="验收负责人:">
            <template #default>
              <div>{{ formInfoObj.checkResponerName }}</div>
            </template>
          </van-cell>

          <van-cell title="验收意见:">
            <template #default>
              <div>
                {{ formInfoObj.checkResponerStatus == '2' ? '通过' : '未通过' }}
              </div>
            </template>
          </van-cell>
          <van-cell title="验收备注:">
            <template #default>
              <div>{{ formInfoObj.checkResponerRemark }}</div>
            </template>
          </van-cell>
          <van-cell title="联系方式:">
            <template #default>
              <div>{{ formInfoObj.checkResponerPhone }}</div>
            </template>
          </van-cell>
          <van-cell title="验收时间:">
            <template #default>
              <div>{{ formInfoObj.checkResponerTime }}</div>
            </template>
          </van-cell>
        </div>
      </div>
    </div>

    <van-goods-action
      v-if="formInfoObj.changeStatus == 1 && !formInfoObj.checkResponerRemark"
    >
      <van-goods-action-button
        :style="{
          background: '#F5F7F6',
          color: '#3A3D3C',
        }"
        type="danger"
        text="撤销登记"
        @click="onClickButton"
      />
    </van-goods-action>
  </div>
</template>
<script>
import { hiddenDangerApi, getHiddenDangerApi } from '@/api/index'
import navBar from '@/components/navBar.vue'
export default {
  name: 'problemDetail',
  props: {},
  components: {
    navBar,
  },
  data() {
    return {
      formInfoObj: {},
      imgList: [],
      imgList2: [],
    }
  },
  created() {
    this.getHiddenDanger()
  },
  methods: {
    async onClickButton() {
      const res = await hiddenDangerApi({
        id: +this.$route.query.id,
        delFlag: 1,
      })
      if (res.code == 0) {
        this.$toast.success('撤销成功')
        this.$router.push('/index')
      } else {
        this.$toast.fail('撤销失败')
      }
    },

    async getHiddenDanger() {
      const res = await getHiddenDangerApi({
        id: this.$route.query.id,
      })
      this.formInfoObj = res.data
      // 定义前缀
      const keysToExtract = ['dangerImg1', 'dangerImg2', 'dangerImg3']
      // 动态提取所有以特定前缀开头的键值对
      this.imgList = keysToExtract
        .filter(
          (key) =>
            res.data[key] !== null &&
            res.data[key] !== '' &&
            res.data[key] !== undefined
        )
        .map((key) => res.data[key])
      const keysToExtract2 = [
        'changeResponerImg1',
        'changeResponerImg2',
        'changeResponerImg3',
      ]
      // 动态提取所有以特定前缀开头的键值对
      this.imgList2 = keysToExtract2
        .filter(
          (key) =>
            res.data[key] !== null &&
            res.data[key] !== '' &&
            res.data[key] !== undefined
        )
        .map((key) => ({ url: res.data[key] }))
    },
  },
  mounted() {},
  watch: {},
  computed: {},
  filters: {},
}
</script>

<style scoped lang="scss">
.my-swipe {
  height: 200px;
  .van-swipe-item {
    color: #fff;
    font-size: 20px;
    line-height: 150px;
    text-align: center;
    background-color: transparent;
  }
  ::v-deep .van-swipe__indicators {
    bottom: 32px;
  }
}
.mainBox {
  background: #f7f7f7;
  border-radius: 16px 16px 0 0;
  padding: 16px;
  transform: translateY(-20px);
  box-sizing: border-box;
  .title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 18px;
    font-weight: bold;
    color: #2f3331;
    margin-bottom: 12px;
    .status {
      width: 52px;
      height: 24px;
      background: #00b9c7;
      border-radius: 4px;
      font-size: 12px;
      color: #fff;
      text-align: center;
      line-height: 24px;
    }
  }
  .problemDesc {
    // width: 343px;
    height: 80px;
    background: #ffffff;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
    // box-sizing: border-box;
  }
}
.formBox {
  // padding: 16px;
  background: #f7f7f7;
  padding-bottom: 60px;
  .formTitle {
    font-weight: bold;
    font-size: 16px;
    color: #2f3133;
    margin-bottom: 16px;
  }
  .formItem {
    border-radius: 10px; /* 设置圆角大小 */
    overflow: hidden; /* 隐藏超出部分 */
    background-color: #fff; /* 可选：设置背景颜色 */
    margin-bottom: 12px;
    .inputCss {
      border: none;
      outline: none;
      background: transparent;
      font-size: 14px;
      text-align: right; /* 添加这行代码 */
    }
    .cellCss {
      box-sizing: border-box;
      width: 100%;
      padding: 10px 16px;
      overflow: hidden;
      color: #323233;
      font-size: 14px;
      line-height: 24px;
      background-color: #fff;
      .cellCssTitle {
        margin-bottom: 10px;
      }
      textarea {
        width: 100%;
        border: none;
      }
    }
  }
}
.swiperImg {
  width: 100%;
  height: 100%;
}
</style>
